INSTALL = @INSTALL@
MKDIR_P = mkdir -p
VIEWERDIR = $(DESTDIR)@prefix@/viewer
CP = /bin/cp
INSTALL_BUNDLE ?= "bundle:min"
CYBERCHEF_VERSION=10.19.2


all: arkimeparser.js

arkimeparser.js: arkimeparser.jison
	jison arkimeparser.jison

check:
	npm ci
	npm run bundle

cyberchef:
	(cd public ; if [ ! -f CyberChef_v$(CYBERCHEF_VERSION).zip ]; then wget -nv -N https://github.com/gchq/CyberChef/releases/download/v$(CYBERCHEF_VERSION)/CyberChef_v$(CYBERCHEF_VERSION).zip; fi)

install: cyberchef
	$(MKDIR_P) "$(VIEWERDIR)" "$(VIEWERDIR)/vueapp"
	/bin/rm -f $(VIEWERDIR)/public/style.css
	$(INSTALL) *.js package.json package-lock.json $(VIEWERDIR)
	npm ci
	npm run $(INSTALL_BUNDLE)
	$(CP) -pr views public $(VIEWERDIR)
	$(CP) -pr vueapp/dist "$(VIEWERDIR)/vueapp"
	(cd $(VIEWERDIR) ; npm ci --omit=dev)

distclean realclean clean:
	rm -rf node_modules
	rm -rf bundle
	(cd vueapp ; rm -rf node_modules ; rm -rf dist)
